from django.db import models

# Create your models here.
from django.contrib.auth.models import AbstractUser
from utils.models import CoreModel
from utils.tools import media_file_name

class Users(AbstractUser, CoreModel):
    username = models.CharField(
        max_length=150,
        unique=True,
        db_index=True,
        verbose_name="用户账号",
        help_text="用户账号",
    )
    email = models.EmailField(
        max_length=255, verbose_name="用户邮箱", null=True, blank=True, help_text="用户邮箱"
    )
    user_pic  = models.ImageField(upload_to="avatars/", verbose_name="用户头像", default="avatars/default.jpg",null=True, blank=True, help_text="用户头像")
    nickname = models.CharField(max_length=40, null=True, blank=True,verbose_name="用户昵称", help_text="用户昵称")
    status = models.BooleanField(default=True, verbose_name="状态", help_text="状态")
    GENDER_CHOICES = (
        (0, "女"),
        (1, "男"),
    )
    gender = models.IntegerField(
        choices=GENDER_CHOICES,
        default=1,
        verbose_name="性别",
        null=True,
        blank=True,
        help_text="性别",
    )

    class Meta:
        db_table = "system_users"
        verbose_name = "用户管理"
        verbose_name_plural = verbose_name
        ordering = ("-create_datetime",)

    def __str__(self) -> str:
        return self.username
    
    
class FileModel(CoreModel):
    name = models.CharField(max_length=255, null=True, blank=True, verbose_name="实际名称", help_text="实际名称")
    save_name = models.CharField(max_length=255, null=True, blank=True, verbose_name="存储名称", help_text="存储名称")
    url = models.FileField(upload_to=media_file_name,verbose_name="上传文件", help_text="上传文件")
    size = models.BigIntegerField(null=True, blank=True, verbose_name="大小", help_text="大小")
    md5sum = models.CharField(max_length=36, blank=True, verbose_name="文件md5", help_text="文件md5")

    class Meta:
        db_table = 'system_file'
        verbose_name = '文件管理'
        verbose_name_plural = verbose_name
        ordering = ('-create_datetime',)
    
